﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using lumo;
using lumo.display.object2D;
using Microsoft.Xna.Framework.Graphics;

namespace game.character.bullet
{
    /// <summary>
    /// 
    /// </summary>
    public class BulletManager : ParticleEmitter
    {
        /// <summary>
        /// Update the bullets.
        /// </summary>
        /// <param name="Game"></param>
        public override void Update(LumoComponent Game)
        {
            foreach (Bullet bullet in ParticleList.Cast<Bullet>())
            {
                bullet.Update(Game, this);
            }
            foreach (Bullet bullet in ParticleList.Where(particle => !particle.Alive))
            {
                bullet.OnDestroy();
            };
            ParticleList.RemoveAll(particle => !particle.Alive);
        }

        /// <summary>
        /// Draw the bullets.
        /// </summary>
        /// <param name="SpriteBatch">The sprite batch object.</param>
        public override void Draw(SpriteBatch SpriteBatch)
        {
            if (Visible)
            {
                foreach (Bullet bullet in ParticleList.Cast<Bullet>())
                {
                    SpriteBatch.Draw(bullet.Texture, bullet.LinearPosition - Global.Camera.ScreenPosition, bullet.SrcRect, bullet.Color * bullet.Opacity, bullet.Rotation, bullet.Origin, bullet.Scale, SpriteEffects.None, 0f); 
                }
            }
        }
    }
}
